using System.Reflection;
using FluentNHibernate.Cfg;
using NHibernate.Cfg;
using Spring.Data.NHibernate;

namespace Common.Dao
{
    public class FluentNhibernateLocalSessionFactoryObject:LocalSessionFactoryObject
    {
        /// <summary>
        /// Sets the assemblies to load that contain fluent nhibernate mappings.
        /// </summary>
        /// <value>The mapping assemblies.</value>
        public string[] FluentNhibernateMappingAssemblies
        {
            get;
            set;
        }

        protected override void PostProcessConfiguration(Configuration config)
        {
            base.PostProcessConfiguration(config);
            Fluently.Configure(config)
                .Mappings(m =>
                              {
                                  foreach (string assemblyName in FluentNhibernateMappingAssemblies)
                                  {
                                      m.HbmMappings
                                          .AddFromAssembly(Assembly.Load(assemblyName));

                                      m.FluentMappings
                                          .AddFromAssembly(Assembly.Load(assemblyName));
                                  }
                              })
                .BuildConfiguration();
        }
    }
}